package com.example.demo.service;

import com.example.demo.mapper.MovieMapper;
import com.example.demo.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @创建人: ZS
 * @创建时间: 2021/4/2
 * @描述:
 */
@Service
public class MovieService implements MovieMapper {
    @Autowired
    MovieMapper movieMapper;
    Page pages = new Page();
//    public List<MovieImg> findAllImg(){
//        List<MovieImg> imgs = movieMapper.findAllImg();
//        for(int i=0;i< imgs.size();i++){
//            imgs.set(i, new MovieImg(String.valueOf(imgs.get(i)).substring(15).replace(")","")+"@1l_1e_1c_128w_180h"));
//        }
//        return imgs;
//    }
    public Page getRyPage(int page){
        pages.setPage(page);
        List allData = movieMapper.findAllRy();
        int len = allData.size();
        if (len%12>0) {
            pages.setPageMax((len/12)+1);
        }else {
            pages.setPageMax(len/12);
        }
        return pages;
    }
    public Page getSyPage(int page){
        pages.setPage(page);
        List allData = movieMapper.findAllSy();
        int len = allData.size();
        if (len%12>0) {
            pages.setPageMax((len/12)+1);
        }else {
            pages.setPageMax(len/12);
        }
        return pages;
    }
    public Page getYpPage(int page){
        pages.setPage(page);
        List allData = movieMapper.findAllYp();
        int len = allData.size();
        if (len%12>0) {
            pages.setPageMax((len/12)+1);
        }else {
            pages.setPageMax(len/12);
        }
        return pages;
    }
    public List<Movie> findAllRy(){return movieMapper.findAllRy();}
    public List<Movie> findAllSy(){return movieMapper.findAllSy();}
    public List<Movie> findAllYp(){return movieMapper.findAllYp();}
    public List<Product> findAllProduct(){return movieMapper.findAllProduct();}
    public List<Lists> findAllLists(){return movieMapper.findAllLists();}
    public List<HeaderImg> findImg(){return movieMapper.findImg();}
    @Override
    public List<Movie> queryMoviesRy(int page) {
        List<Movie> movies = movieMapper.queryMoviesRy((page-1)*12);
        return movies;
    }
    @Override
    public List<Movie> queryMoviesSy(int page) {
        List<Movie> movies = movieMapper.queryMoviesSy((page-1)*12);
        return movies;
    }
    @Override
    public List<Movie> queryMoviesYp(int page) {
        List<Movie> movies = movieMapper.queryMoviesYp((page-1)*12);
        return movies;
    }
    @Override
    public List<Movie> findMovieRy(int id) {
        List<Movie> movies = movieMapper.findMovieRy(id);
        return movies;
    }
    @Override
    public List<Movie> findMovieSy(int id) {
        List<Movie> movies = movieMapper.findMovieSy(id);
        return movies;
    }
    @Override
    public List<Movie> findMovieYp(int id) {
        List<Movie> movies = movieMapper.findMovieYp(id);
        return movies;
    }
    @Override
    public List<Movie> findMovie(int id) {
        List<Movie> movies = movieMapper.findMovie(id);
        return movies;
    }
    @Override
    public List<Movie> searchMovie(String name) {
        List<Movie> movies = movieMapper.searchMovie(name);
        return movies;
    }
}
